package gui.common;

/**
 * Tagable is the base class for all classes used to pass data into views. Tagable subclasses
 * contain the data that will be displayed by views. The Tag property is used to link Tagable
 * objects back to the model objects they represent.
 * 
 * @param <T>
 *          The type of object that this taggable represents
 */
public class Taggable<T>
{

  /**
   * Tag property. Reference to a model object corresponding to this object.
   */
  private T _tag;

  /**
   * Constructs an empty Tagable object.
   * 
   * {@pre None}
   * 
   * {@post getTag() == null}
   */
  public Taggable()
  {
    _tag = null;
  }

  /**
   * Sets the Tag property.
   * 
   * @param value
   *          new value for the Tag property
   * 
   *          {@pre None}
   * 
   *          {@post getTag() == value}
   */
  public void setTag(T value)
  {
    _tag = value;
  }

  /**
   * Returns the current value of the Tag property.
   * 
   * {@pre None}
   * 
   * {@post Returns the current value of the Tag property.}
   */
  public T getTag()
  {
    return _tag;
  }

  /**
   * Returns true if and only if Tag is not null.
   * 
   * {@pre None}
   * 
   * {@post Returns true if and only if Tag is not null}
   */
  public boolean hasTag()
  {
    return (_tag != null);
  }

  @Override
  public int hashCode()
  {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((this._tag == null) ? 0 : this._tag.hashCode());
    return result;
  }

  @SuppressWarnings("rawtypes")
  @Override
  public boolean equals(Object obj)
  {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (!(obj instanceof Taggable))
      return false;
    Taggable other = (Taggable) obj;
    if (this._tag == null && other._tag != null)
      return false;
    else if (!this._tag.equals(other._tag))
      return false;
    return true;
  }
}
